package com.huidao.service;

import java.util.List;

import com.huidao.dao.OrderDao;
import com.huidao.dao.OrderDaoImp;
import com.huidao.entity.Order;

public class OrderServiceImp implements OrderService {

	private static OrderDao dao = new OrderDaoImp() ;
	private static int pagesize=5;
		
	@Override
	public String addOrder(Order order) {
		if(dao.addOrder(order)){
			return "";
		}else{
			return "添加失败";
		}
	}

	public String updateOrder(Order order) {
		if(dao.updateOrder(order)){
			return "";
		}else{
			return "修改失败";
		}
	}

	@Override
	public List<Order> getListOrder(int currenpage) {
		return dao.getListOrder(currenpage, pagesize);
	}

	@Override
	public int total(int currenpage) {
		int total=dao.total(currenpage, pagesize);
		if(total%pagesize==0){
			return total/pagesize;
		}else{
			return total/pagesize+1;
		}
	}
	
	public double getTotalPrice(){
		List<Order> list=dao.getListOrder(1, total(1));
		double totalPrice = 0;
		for (Order order : list) {
			totalPrice+=order.getGoods_num()*order.getGoods().getgPrice();
		}
		return totalPrice;
	}
}
